% orig https://zhuanlan.zhihu.com/p/500426271
function [C]=BSpline(varargin)
narginchk(1,7);
ctrls=varargin{1};
k=varargin{2};
flag=varargin{3};
drawable=varargin{4};

weights=ones(size(ctrls,1),1)*(1/size(ctrls,1));
n=size(ctrls,1)-1;
switch flag
    case 1
        NodeVector = linspace(0, 1, n+k+2); % 均匀B样条的节点矢量
    case 2
        NodeVector = U_quasi_uniform(n, k); % 准均匀B样条的节点矢量
    case 3
        NodeVector = U_piecewise_Bezier(n, k); % 分段Bezier曲线的节点矢量
    case 4
        NodeVector=varargin{5}; %非均匀有理B样条 NURBS
        weights=varargin{6};
    otherwise
        fprintf('error!\n');
end

C=BSpline_gen(ctrls,n,k,NodeVector,0.001,weights);

%绘制结果
if drawable
    DisSpline(ctrls, n,C);
end

end